home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmiSoft / Dev / Lang / Nano.lha / nano / prog / calendar.n < prev    next >
Encoding:
Text File  |  2002-11-18  |  6.6 KB  |  362 lines

  1. //  This program creates a calendar. The data is taken from
  2. //  a math-book.
  3. //
  4. //  ranges:
  5. //  century:    15 - 32
  6. //  year:        0 - 99
  7. //  month:       1 - 12
  8. //  day:         1 - 31
  9. //
  10. //  change user settings
  11. //
  12.  
  13. int days[7][5]; int centurys[5][7]; int scenturys[4]; int years[7][18];
  14. int months[7][7]; int monthd[7][3]; int data[7][7];
  15.  
  16. int century; int year; int month; int day; int dayname; int row; int col;
  17. int i; int j; int x; int ok; int data1; int data2; int leapyear;
  18. int ch1; int ch2;
  19. int monday; int tuesday; int wednesday; int thursday; int friday;
  20. int saturday; int sunday; int null;
  21.  
  22.  
  23. // calendar
  24.  
  25. int monthlen[12]; int cal[12][42]; int cal2[12][7][6];
  26. int mstart; int cmonth; int cmonthpos; int cdays;
  27. int borderl; int bordert; int borderb; int borderm; int maxline;
  28.  
  29.  
  30. // USER SETTINGS --------------------------------------------------------
  31.  
  32. maxline = 72;   number of lines per page
  33. borderl = 8;    left border
  34. bordert = 4;    top border
  35.  
  36. // DONT CHANGE ANYTHING BELOW! ------------------------------------------
  37.  
  38. borderb = maxline -- bordert; borderb = borderb -- 47;
  39.  
  40. monthlen[0] = 31; monthlen[1] = 28; monthlen[2] = 31;
  41. monthlen[3] = 30; monthlen[4] = 31; monthlen[5] = 30;
  42. monthlen[6] = 31; monthlen[7] = 31; monthlen[8] = 30;
  43. monthlen[9] = 31; monthlen[10] = 30; monthlen[11] = 31;
  44.  
  45. string date[13]; string y[5]; string filen[13];
  46.  
  47. #include <spl_date.dec>
  48. #include <datedata.n>
  49.  
  50. lab start;
  51.  
  52. leapyear = 0;
  53.  
  54. print /n;
  55. ok = 0;
  56. while ok != 1;
  57.     y = "";
  58.     input "year: yyyy   (RETURN to exit): " y;
  59.     if y = ""; exit; endif;
  60.     date = "01.01." + y;
  61.     call spl_date (day, month, year, century, date);
  62.     if day != -1;
  63.         ch1 = year >= 0; ch2 = year <= 99;
  64.         ok = ch1 and ch2;
  65.         if ok != 1;
  66.             print "year range: 0 - 99", /n;
  67.         endif;
  68.  
  69.         ch1 = century >= 15; ch2 = century <= 32;
  70.         ok = ch1 and ch2;
  71.         if ok != 1;
  72.             print "century range: 15 - 32", /n;
  73.         endif;
  74.     endif;
  75. wend;
  76.  
  77. filen = "cal_" + y; filen = filen + ".txt";
  78.  
  79. ok = 0;
  80. i = 0;
  81. while ok = 0;
  82.     j = 0;
  83.     while j <= 4;
  84.         x = days[i][j];
  85.         if x = day;
  86.             row = i;
  87.             ok = 1;
  88.         endif;
  89.         inc j;
  90.     wend;
  91.  
  92.     if i < 6;
  93.         inc i;
  94.     endif;
  95.     if i > 6;
  96.         ok = 1;
  97.     endif;
  98. wend;
  99.  
  100.  
  101. // check if leapyear
  102.  
  103. i = 0;
  104. while i <= 3;
  105.     x = scenturys[i];
  106.     if x = century;
  107.         if year = 0;
  108.             leapyear = 1;
  109.         endif;
  110.     endif;
  111.     inc i;
  112. wend;
  113.  
  114. x = year mod 4;
  115. if x = 0;
  116.     leapyear = 1;
  117. endif;
  118.  
  119. ok = 0;
  120. i = 0;
  121. while ok = 0;
  122.     j = 0;
  123.     while j <= 2;
  124.         x = monthd[i][j];
  125.         if x = month;
  126.             col = i;
  127.             ok = 1;
  128.         endif;
  129.         inc j;
  130.     wend;
  131.  
  132.     if i < 6;
  133.         inc i;
  134.     endif;
  135.     if i > 6;
  136.         ok = 1;
  137.     endif;
  138. wend;
  139.  
  140. if leapyear;
  141.     if month = 1;
  142.         col = 1;
  143.     endif;
  144.     if month = 2;
  145.         col = 3;
  146.     endif;
  147. endif;
  148.  
  149. data1 = months[row][col];
  150.  
  151. ok = 0;
  152. i = 0;
  153. while ok = 0;
  154.     j = 0;
  155.     while j <= 17;
  156.         x = years[i][j];
  157.         if x = year;
  158.             row = i;
  159.             ok = 1;
  160.         endif;
  161.         inc j;
  162.     wend;
  163.  
  164.     if i < 6;
  165.         inc i;
  166.     endif;
  167.     if i > 6;
  168.         ok = 1;
  169.     endif;
  170. wend;
  171.  
  172. ok = 0;
  173. i = 0;
  174. while ok = 0;
  175.     j = 0;
  176.     while j <= 5;
  177.         x = centurys[i][j];
  178.         if x = century;
  179.             col = j;
  180.             ok = 1;
  181.         endif;
  182.         inc j;
  183.     wend;
  184.  
  185.     if i < 4;
  186.         inc i;
  187.     endif;
  188.     if i > 4;
  189.         ok = 1;
  190.     endif;
  191. wend;
  192.  
  193. data2 = data[row][col];
  194. dayname = data1 + data2;
  195.  
  196. ok = 0;
  197. i = 0;
  198. while ok = 0;
  199.     j = 0;
  200.     while j <= 4;
  201.         x = days[i][j];
  202.         if x = dayname;
  203.             row = i;
  204.             ok = 1;
  205.         endif;
  206.         inc j;
  207.     wend;
  208.  
  209.     if i < 6;
  210.         inc i;
  211.     endif;
  212.     if i > 6;
  213.         ok = 1;
  214.     endif;
  215. wend;
  216.  
  217. dayname = row;
  218.  
  219.  
  220. // calendar - part
  221. // fill cal array
  222.  
  223. init cal 0;
  224. cmonth = month -- 1;
  225.  
  226. mstart = dayname -- 1;
  227. if dayname = sunday;
  228.     mstart = 6;
  229. endif;
  230.  
  231. while cmonth <= 11;
  232.     cdays = monthlen[cmonth];
  233.     if leapyear;
  234.         if cmonth = 1;
  235.             inc cdays;
  236.         endif;
  237.     endif;
  238.  
  239.     i = mstart; j = 1;
  240.     while j <= cdays;
  241.         cal[cmonth][i] = j;
  242.         inc i;
  243.         inc j;
  244.     wend;
  245.  
  246.     if i > 34;
  247.         mstart = 41 -- i;
  248.     endif;
  249.     if i <= 34;
  250.         mstart = 34 -- i;
  251.     endif;
  252.     mstart = 6 -- mstart;
  253.     inc cmonth;
  254. wend;
  255.  
  256.  
  257. // print calendar
  258. // copy to 2dimens for easy printing
  259.  
  260. cmonth = 0;
  261. while cmonth <= 11;
  262.     i = 0;
  263.     col = 0;
  264.     while col <= 5;
  265.         row = 0;
  266.         while row <= 6;
  267.             day = cal[cmonth][i];
  268.             cal2[cmonth][row][col] = day;
  269.             inc i;
  270.             inc row;
  271.         wend;
  272.         inc col;
  273.     wend;
  274.     inc cmonth;
  275. wend;
  276.  
  277. print "writing to '", filen, "' ...", /n;
  278. fopen 1, filen, "w";
  279.  
  280. fwrite 1, /n bordert;
  281. fwrite 1, /s borderl, /s30, century;
  282. if year <= 9;
  283.     fwrite 1, null;
  284. endif;
  285. fwrite 1, year, /n3;
  286.  
  287. borderm = borderl + 5;
  288.  
  289. i = 1; cmonthpos = 0;
  290. while i <= 4;
  291.     if i = 1;
  292.         fwrite 1, /s borderm, "January", /s12, "February", /s11, "March", /n2;
  293.         goto endm;
  294.     endif;
  295.     if i = 2;
  296.         fwrite 1, /s borderm, "April", /s14, "May", /s16, "June", /n2;
  297.         goto endm;
  298.     endif;
  299.     if i = 3;
  300.         fwrite 1, /s borderm, "July", /s15, "August", /s13, "September", /n2;
  301.         goto endm;
  302.     endif;
  303.     if i = 4;
  304.         fwrite 1, /s borderm, "October", /s12, "November", /s11, "December", /n2;
  305.     endif;
  306.  
  307.     lab endm;
  308.  
  309.     row = 0;
  310.     while row <= 6;
  311.         fwrite 1, /s borderl;
  312.  
  313.         if row = 0; fwrite 1, "mon"; goto endd; endif;
  314.         if row = 1; fwrite 1, "tue"; goto endd; endif;
  315.         if row = 2; fwrite 1, "wed"; goto endd; endif;
  316.         if row = 3; fwrite 1, "thu"; goto endd; endif;
  317.         if row = 4; fwrite 1, "fri"; goto endd; endif;
  318.         if row = 5; fwrite 1, "sat"; goto endd; endif;
  319.         if row = 6; fwrite 1, "sun"; endif;
  320.  
  321.         lab endd;
  322.  
  323.         fwrite 1,  "|";
  324.  
  325.         j = 1;
  326.         cmonth = cmonthpos;
  327.         while j <= 3;
  328.             col = 0;
  329.             while col <= 5;
  330.                 day = cal2[cmonth][row][col];
  331.                 if day > 0;
  332.                     if day <= 9;
  333.                         fwrite 1, /s;
  334.                     endif;
  335.                     fwrite 1, day;
  336.                     goto nextcol;
  337.                 endif;
  338.                 fwrite 1, /s2;
  339.  
  340.                 lab nextcol;
  341.  
  342.                 fwrite 1, /s;
  343.                 inc col;
  344.             wend;
  345.             fwrite 1, "|";
  346.             inc j;
  347.             inc cmonth;
  348.         wend;
  349.         fwrite 1, /n;
  350.         inc row;
  351.     wend;
  352.     fwrite 1, /n2;
  353.     inc i;
  354.     cmonthpos = cmonthpos + 3;
  355. wend;
  356. fwrite 1, /n borderb;
  357. fclose 1;
  358. exit;
  359.  
  360. #include <spl_date.sub>
  361.  
  362.